package google._2016.roundC;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class GGame {
	
	private static boolean possible = false;
	private static int[][] map = null;
	private static int counts = 0;
	private static boolean[] seats = null;
	private static boolean[][] might  = null;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("resources/C-small-practice.in"));
        FileWriter out = new FileWriter("resources/C-small-practice.out");
        int T = Integer.valueOf(in.readLine().trim());
        for(int i = 1; i <= T; i++) {
            out.write("Case #" + i + ": ");
            run(in, out);
            out.write("\n");
        }
        in.close();
        out.flush();
        out.close();
	}
	
	private static void run(BufferedReader in, FileWriter out) throws IOException {
		possible = false;
		
		String[] tmp = in.readLine().trim().split(" ");
		int n = Integer.valueOf(tmp[0]);
		int m = Integer.valueOf(tmp[1]);
		counts = 1 << n;
		map = new int[counts][counts];
		
		for (int i = 0; i < m; i++) {
			tmp = in.readLine().trim().split(" ");
			int e = Integer.valueOf(tmp[0]) - 1;
			int k = Integer.valueOf(tmp[1]);
			int b = Integer.valueOf(tmp[2]);
			tmp = in.readLine().trim().split(" ");
			for (int j = 0; j < b; j++) {
				int f = Integer.valueOf(tmp[j]) - 1;
				map[e][f] = (1 << k);
				map[f][e] = (1 << k);
			}
		}
		might = new boolean[counts][counts];
		seats = new boolean[counts];
		for (int i = 0; i < counts; i++)
			seats[i] = true;
		for (int i = 0; i < counts; i++)
			for (int j = 0; j < counts; j++)
				might[i][j] = true;
		
		check(0);
		
		if (possible)
			out.write("YES");
		else
			out.write("NO");
	}
	
	private static void check(int now) {
		if (now >= counts) {
			possible = true;
			return;
		}
		if (possible)
			return;
		
		for (int i = 0; i < counts; i++)
			if (seats[i] && might[now][i]) {
				boolean[][] _might = new boolean[counts - now - 1][counts];
				for (int j = now + 1; j < counts; j++) {
					for (int p = 0; p < counts; p++)
						_might[j - now - 1][p] = might[j][p];
					for (int p = Math.max(0, now - map[now][j] + 1); p < Math.min(counts, now + map[now][j]); p++)
						might[j][p] = false;
				}
				seats[i] = false;
				check(now + 1);
				if (possible)
					return;
				
				seats[i] = true;
				for (int j = now + 1; j < counts; j++)
					for (int p = 0; p < counts; p++)
						might[j][p] = _might[j - now - 1][p];
			}
	}

}
